<div class="doc-item" id="doc-1058"><h2 class="doc-item-name">monad-transformer<span class="namespace">(clojure.contrib.monads)</span></h2><p class="macro">Macro</p><ul class="var-arglists"><li>(<span class="var-name">monad-transformer</span> base which-m-plus operations)</li></ul><div class="var-docstring"><p>Define a monad transforer in terms of the monad operations and the base
    monad. The argument which-m-plus chooses if m-zero and m-plus are taken
    from the base monad or from the transformer.</p></div><div class="var-source"><pre>; clojure/contrib/monads.clj:433
(defmacro monad-transformer
  [base which-m-plus operations]
  `(let [which-m-plus# (cond (= ~which-m-plus :m-plus-default)
			       (if (= ::undefined (with-monad ~base ~'m-plus))
			         :m-plus-from-transformer
			         :m-plus-from-base)
			     (or (= ~which-m-plus :m-plus-from-base)
				 (= ~which-m-plus :m-plus-from-transformer))
			       ~which-m-plus
			     :else
			       (throw (java.lang.IllegalArgumentException.
				       &quot;undefined m-plus choice&quot;)))
	 combined-monad# (monad ~operations)]
    (if (= which-m-plus# :m-plus-from-base)
      (assoc combined-monad#
	:m-zero (with-monad ~base ~'m-zero)
	:m-plus (with-monad ~base ~'m-plus))
      combined-monad#)))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>